<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.user.dto.RegisterUserQueryDTO"%>
<%@page import="com.sinba.common.user.service.IRegisterUserService"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>

<%
if(session.getAttribute("password2")==null){
	/* response.sendRedirect( "login2.jsp?pageUrl=user/recommend.jsp");
	return; */
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
IRegisterUserService registerUserService = (IRegisterUserService)ac.getBean("registerUserService");
RegisterUserQueryDTO qdto = new RegisterUserQueryDTO();
qdto.setLoginName((String)session.getAttribute("loginName"));
int pages = 1;
String sidx = "status";
String sord="desc";
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
qdto.setStart( start );
qdto.setLimit( rows );
PageDTO pageDTO = registerUserService.findDirectPushUserPager(qdto, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);
session.setAttribute("middle", "业务管理");
session.setAttribute("end", "我的推荐");

String loginName = (String)session.getAttribute("loginName");
//我推荐已激活
Integer recommendQuy = registerUserService.userCount(loginName,"AllRecActivation",null);
request.setAttribute("recommendQuy",recommendQuy);
request.setAttribute("pageUrl","recommend.jsp?loginName="+ loginName);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.salesTotal"/>-<fmt:message key="i18n.title"/> </title>
<link rel="shortcut icon" href="../index/favicon.png" />
<jsp:include page="common.jsp"></jsp:include>
</head>
<body>
<jsp:include page="page_head.jsp"></jsp:include>
<div class="row">
	<div class="col-md-12">
	<div class="box border primary">
			<div class="box-title">
				<h4>
					<i class="fa fa-columns"></i> <span
						class="hidden-inline-mobile"><span><fmt:message key="i18n.myTuiJian"/> (<fmt:message key="i18n.totalRecommend"/>：${pageDTO.totalSize})</span>
				</h4>
			</div>
			<div class="box-body">
				<div class="tabbable">
					<ul class="nav nav-tabs">
						<li class="active"><a href="#yunYing"
							data-toggle="tab"><i class="fa fa-signal"></i> <span
								class="hidden-inline-mobile"><fmt:message key="i18n.myTuiJian"/></span></a></li>
					</ul>
					<div class="tab-content">
						<div class="tab-pane active" id="yunYing">
							<table
								class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th scope="col"><fmt:message key="i18n.userId"/></th>
										<th scope="col"><fmt:message key="i18n.piUserName"/></th>
										<%-- <th scope="col"><fmt:message key="i18n.userlevel"/></th> --%>
									    <th scope="col"><fmt:message key="i18n.firstSingle" /></th>
										<th scope="col"><fmt:message key="i18n.regTime"/></th>
										<th scope="col"><fmt:message key="i18n.status"/></th>
										<%-- <th scope="col"><fmt:message key="i18n.operation"/></th> --%>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${pageDTO.data}" var="data">
							  			<tr>
											<td>${data.loginName}</td>
											<td>${data.userName}</td>
											<%-- <td><fmt:message key="${data.registerLevel}" /></td> --%>
								        	<td>${data.registerMoney}</td>
											<td><fmt:formatDate value="${data.registerTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
											<td>
											<c:if test="${data.status eq 'Activation'}" ><fmt:message key="i18n.yijihua"/></c:if>
											<c:if test="${data.status ne 'Activation'}" ><span style="color: red;"><fmt:message key="i18n.weijihua"/></span></c:if>
											</td>
											<%-- <td>
											<c:if test="${data.status ne 'Activation'}">
											<a id="acuser_${data.registerUserId}" href="javascript:accountActivate('${data.loginName}','${data.registerUserId}');">[<fmt:message key="i18n.clickJihuo"/>]</a>
											&nbsp;&nbsp;
											<a href="javascript:delateRegister('${data.loginName}');">[<fmt:message key="i18n.delete"/>]</a></c:if>
											</td> --%>
										</tr>
									</c:forEach>
									<c:if test="${empty pageDTO.data}">
											<tr>
												<td colspan="5" align="center">没有数据</td>
											</tr>
									</c:if>
									<tr>
											<td colspan="9" style="text-align: right;">
											<a style="color: blue;" href="${pageUrl }&pages=1"><fmt:message key="i18n.firstPage"/></a>
											<c:if test="${pageDTO.page > 1}">
												<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a>
											</c:if>
											<a>${pageDTO.page}/${pageDTO.total}</a>
											<c:if test="${pageDTO.page+1<=pageDTO.total}">
												<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a>
											</c:if>
											<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a>
											<a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a>
											</td>
										</tr>
								</tbody>
							</table>
						</div>
						
       	<form  action="registerUser!userOpt.action" method="post" id="userActivate_form" ></form>
       	<form  action="registerUser!userOpt.action" method="post" id="deleteReguser_form" ></form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
function accountActivate(loginName,userId){
	$('#userActivate_form').html("<input type='hidden' name='pageUrl' value='recommend.jsp' />"+
			"<input type='hidden' name='activeType' value='RecommendUser' />"+
			"<input type='hidden' name='registerUserDTO.loginName' value='"+loginName+"' />");
	if(confirm('Are you sure you want to activate(是否确定要激活)?')){
		$('#acuser_'+userId).attr("disabled",true);
		$('#userActivate_form').submit();
	}
}

function delateRegister(loginName){
	$('#deleteReguser_form').html("<input type='hidden' name='pageUrl' value='declarationCenter.jsp' />"+
			"<input type='hidden' name='registerUserDTO.loginName' value='"+loginName+"' />");
	if(confirm('Are you sure you want to delete(是否确定要删除)?')){
		$('#deleteReguser_form').submit();
	}
}
</script>


</body>
</html>